package com.cskaoyan.controller;

import com.cskaoyan.bean.BO.OrderCommentBo;
import com.cskaoyan.bean.BO.OrderDeleteBo;
import com.cskaoyan.bean.BO.OrderSubmitBo;
import com.cskaoyan.bean.PO.MarketOrderGoods;
import com.cskaoyan.bean.VO.SubmitVo;
import com.cskaoyan.bean.VO.WxOrderDetailVo;
import com.cskaoyan.bean.VO.WxOrderListVo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.WxOrderService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @ClassName WxOrderController
 * @Description TODO
 * @Author ke
 * @Date 2022/8/16 14:45
 * @Version 1.0
 */
@RestController
@RequestMapping("wx/order")
public class WxOrderController {

    @Autowired
    WxOrderService wxOrderService;


    @RequestMapping("list")
    public BaseRespVo list(Integer showType,Integer page,Integer limit){


        Subject subject = SecurityUtils.getSubject();
        Session session = subject.getSession();
        String username = (String) session.getAttribute("username");

        // String username="user123";

        CommonData<WxOrderListVo> commonData = wxOrderService.list(username,showType,page,limit);

        return BaseRespVo.ok(0,commonData,"成功");
    }


    @RequestMapping("detail")
    public BaseRespVo detail(Integer orderId){
      WxOrderDetailVo vo= wxOrderService.detail(orderId);
      return BaseRespVo.ok(0,vo,"成功");
    }

    @RequestMapping("refund")
    public BaseRespVo refund(@RequestBody OrderDeleteBo bo){
        Integer orderId = bo.getOrderId();
        int code = wxOrderService.refund(orderId);
        return BaseRespVo.ok(0,null,"成功");
    }


    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody OrderDeleteBo bo){
        Integer orderId = bo.getOrderId();
        int code = wxOrderService.delete(orderId);
        return BaseRespVo.ok(0,null,"成功");
    }

    @RequestMapping("confirm")
    public BaseRespVo confirm(@RequestBody OrderDeleteBo bo){
        Integer orderId = bo.getOrderId();
        int code = wxOrderService.confirm(orderId);
        return BaseRespVo.ok(0,null,"成功");
    }

    @RequestMapping("comment")
    public BaseRespVo comment(@RequestBody OrderCommentBo bo){
        int code = wxOrderService.comment(bo);
        return BaseRespVo.ok(0,null,"成功");
    }



    @RequestMapping("cancel")
    public BaseRespVo cancel(@RequestBody OrderDeleteBo bo){
        Integer orderId = bo.getOrderId();
        int code = wxOrderService.cancel(orderId);
        return BaseRespVo.ok(0,null,"成功");
    }

    @RequestMapping("prepay")
    public BaseRespVo prepay(@RequestBody OrderDeleteBo bo){
        Integer orderId = bo.getOrderId();
        int code = wxOrderService.prepay(orderId);
        return BaseRespVo.ok(0,null,"成功");
    }


    @RequestMapping("goods")
    public BaseRespVo goods(Integer orderId,Integer goodsId){

      MarketOrderGoods goods= wxOrderService.goods(orderId,goodsId);

      return BaseRespVo.ok(0,goods,"成功");
    }

    @RequestMapping("submit")
    public BaseRespVo submit(@RequestBody OrderSubmitBo bo) {

        SubmitVo vo = wxOrderService.submit(bo);
        return BaseRespVo.ok(0, vo, "成功");
    }


}
